#coding:utf-8
#!/usr/bin/env python
import wx                               #导入wx包
import jx3_com

class MyLogin(wx.Frame):
	type=0
	msg = ''
	def __init__(self):
		wx.Frame.__init__(self, None, -1, '验证码',size=(240, 200))
		image_file = self.get_img_path()
		try:
			image = wx.Image(image_file, wx.BITMAP_TYPE_PNG)
			self.bitmap =wx.StaticBitmap(self, -1, wx.Bitmap(image),pos=(10,10),size=(200,70))
		except IOError:
			print('Image file %s not found' % image_file)
			raise SystemExit
		self.txt_vfy=wx.TextCtrl(self,pos=(35,90),size=(120,20))
		self.button_fresh = wx.Button(self, -1, label='刷新验证码', size=(80, 20), pos=(10, 120))
		self.Bind(wx.EVT_BUTTON, self.on_btn_fresh, self.button_fresh)
		self.button_ok = wx.Button(self, label = '确定',size=(60,20),pos=(150,120))  #创建Button
		self.Bind(wx.EVT_BUTTON,self. on_btn_ok, self.button_ok)
		
	
	# 三个参数分别是干嘛的  第一个 表示类型是 按键按一下
		# 第二个 表示的是 做什么事情，这是函数需要自己去写
		# 第三个参数表示的应用在哪个东西上 这里是应用在button上这个按键


	
	def on_btn_ok(self, event):
		varify_code = self.txt_vfy.GetValue()
		self.button_ok.SetLabelText(varify_code)
		jx3_com.keyword = varify_code
		self.msg = varify_code
		print('v' + varify_code)
		self.Close(True)
	
	def on_btn_fresh(self):
		image_file = self.get_img_path()
		to_bmp_image = wx.Image(image_file, wx.BITMAP_TYPE_ANY).ConvertToBitmap()
		self.bitmap.SetBitmap(to_bmp_image)
		print(image_file)
	
	def get_img_path(self):
		return jx3_com.get_verify_img()
	
def show():
	app = wx.App()
	frame = MyLogin()
	frame.Show()
	app.MainLoop()
	return frame.msg
	
if __name__=='__main__':
	app=wx.App()
	frame=MyLogin()
	frame.Show()
	app.MainLoop()